<?php

/**
 * Framework_Cache_Handler_Module
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @subpackage Cache
 * @filesource
 */

/**
 * Framework_Cache_Handler_Module
 *
 * Cache handler that handles caching for modules
 *
 * @author 		Ian Szewczyk <roamzero@gmail.com>
 * @package 	Framework
 * @subpackage 	Handler
 */
class Framework_Cache_Handler_Module extends Framework_Cache_Handler_Common  {

	
    /**
     * __construct
     *
     * Initializes the cache handler
     *
     * @access 		public
     * @return 		void
     */
	public function __construct($object)
	{
		parent::__construct($object);
	}
	
	
	/**
     * getCache
     *
     * Returns the name of the cache to be used
     *
     * @access 		public
     * @return 		string 		Name of the cache to use
     */
	public function getCache()
	{
		return $this->object->moduleName;
	}
	
	/**
     * getGroup
     *
     * Returns the name of the group that the data should be cached under
     *
     * @access 		public
     * @return 		string 		Cache group
     */
	public function getGroup()
	{
		if (Framework::$request->ownerName) {
			return Framework::$request->ownerName;
		} else {
			return 'default';
		}
		
	}
	
	/**
	 * setGroup
	 *
	 * Used to set the group the data should be cached under
	 *
	 * @param 		string 		$group
	 * @return 		void
	 */
	public function setGroup($group)
	{
		$this->group = $group;
	}
	
	/**
	 * getID
	 *
	 * Returns the ID under which the data should be cached
	 *
	 * @return 		string
	 */
	public function getID()
	{
		$user = Framework_User::singleton();
		if (Framework::$request->isAjax()) {
			$ajax = 1;
		} else {
			$ajax = 0;
		}
		return md5(Framework::$request->getHTTPPath().$_SERVER['QUERY_STRING'].$user->userStatus.$user->friendStatus.$ajax);
	}
	
	/**
	 * getDataToCache
	 *
	 * Returns the data that needs to be cached for the module
	 *
	 * @return 		array
	 */
	public function getDataToCache()
	{
		
		$data = array(
			'id' => $this->getID(),
			'authClass' => $this->object->authLayer,
			'presenter' => $this->object->presenter,
			'pageTemplate' => $this->object->pageTemplateFile,
			'template' => $this->object->tplFile
		);
		
		return $data;
		
	}
	
	
}


?>